SET SERVEROUTPUT ON 
DECLARE
	--Declaring the variables for the storage of type of table.
	TYPE Starstarname IS TABLE OF star.starname%type;
	TYPE Directordirname IS TABLE OF director.dirname%type;
	TYPE Moviemvname IS TABLE OF movie.mvtitle%type;
	  
	--Reffering the Table Type into variables.
    starname Starstarname;
	movie_name movie.mvtitle%type;

	TYPE movierecord IS RECORD 
	(moviename Moviemvname,
	 directorname Directordirname
	);
       
	mv_data movierecord ;
	
	--Making use of the Cursor in order to fetch the data
    CURSOR movie_data IS
       SELECT mvtitle, dirname
        FROM movie, director
        WHERE movie.dirnumb = director.dirnumb AND
        dirdied IS NULL;
  
	--Making use of the Cursor in order to fetch the data
    CURSOR star_data IS
       SELECT starname
        FROM movie, movstar,star
        WHERE movie.mvnumb = movstar.mvnumb AND
        movstar.starnumb = star.starnumb AND
        movie.mvtitle = movie_name;
  
BEGIN
    OPEN movie_data;
	LOOP
		--Fetching the data from the cursor for Movie collection into the variables.
	    FETCH movie_data BULK COLLECT INTO mv_data;
		FOR i IN 1..mv_data.moviename.COUNT
		LOOP
			--Displaying the Director data.
			DBMS_OUTPUT.PUT_LINE(mv_data.moviename(i)||'directed by '||mv_data.directorname(i));
			DBMS_OUTPUT.PUT_LINE('Stars: ');
			movie_name := mv_data.moviename(i);
			OPEN star_data;
				LOOP						
					--Fetching the data from the cursor for Star collection into the variables.
					FETCH star_data BULK COLLECT INTO starname;
					FOR i IN 1..starname.COUNT
					LOOP
						--Displaying the Star data.
						DBMS_OUTPUT.PUT_LINE(starname(i));
					END LOOP;
					EXIT WHEN star_data%NOTFOUND;
				END LOOP;
					DBMS_OUTPUT.PUT_LINE('------------------------------------------------------');
			CLOSE star_data;
		END LOOP;		 
		EXIT WHEN movie_data%NOTFOUND;
	END LOOP;
    CLOSE movie_data;
  END;
/

